<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="yes" />
<title>信呼</title>
<link rel="stylesheet" type="text/css" href="res/css/webimcss.css"/>
<link rel="shortcut icon" href="favicon.ico" />
<script type="text/javascript" src="res/js/jquery.js"></script>
<script type="text/javascript" src="res/js/js.js"></script>
<script type="text/javascript" src="res/js/base64-min.js"></script>
<script type="text/javascript" src="res/js/nwjs.js"></script>
<style>
.lmaisft{width:400px;border-radius:10px;text-align:left; background-color:#C4E0F4;background: rgba(255,255,255,0.5);box-shadow:0px 0px 10px rgba(0,0,0,0)}
.ltoplog img{border-radius:50%}
</style>
<script>
var temp_token='';
function initbody(){
	systemtitle = js.getoption('systemtitle','信呼');
	resize();
	$(window).resize(resize);
	js.splittime=0;
	var us=js.request('user',js.getoption('adminuser')),murl=js.request('murl');
	temp_token=js.request('token');
	if(murl){
		murl=jm.base64decode(murl);
		js.setoption('apiurl', murl);
		apiurl=murl;
	}
	$('#adminuser').val(us);
	var face = js.getoption('adminface');
	if(face)get('myface').src=face;
	nwjs.init();
	document.title=systemtitle;
	nwjs.createtray(systemtitle, 0);
	if(temp_token.length>=8&&us!=''){
		loginsubmit(0);
	}
	if(nwjs.nw){
		$('#footerts').append(', <a onclick="return clearchater()" href="javascript:;">[清空缓存]</a>, <a onclick="return updatejian(false)" href="javascript:;">[检查更新]</a>');
		var jtd= js.getoption('lastjcupdate');
		if(jtd!=js.now())updatejian(true);//每天检查更新
	}
}
function clearchater(){
	nwjsgui.App.clearCache();
	localStorage.clear();
	var na = nwjsgui.App.manifest.name;
	js.setoption('apiurl', apiurl);
	js.confirm('基本缓存已删除，更多缓存删除，是否打开对应['+na+']目录？需手动全部删除目录。',function(jg){
		if(jg=='yes'){
			var naea = nwjsgui.App.dataPath;
			var oru= naea.split(na)[0]+na;
			nwjsgui.Shell.openItem(oru);
			nwjsgui.App.quit();
		}
	});
}
function getupurl(act){
	return 'http://www.rockoa.com/api.php?a='+act+'&callback=?';
}
var version = '';
function updatejian(upb){
	try{version = nwjs.fs.readFileSync('version.txt');}catch(e){}
	if(!upb)js.msg('wait','检查中...');
	$.getJSON(getupurl('clientupg')+'&version='+version+'',function(a){
		var d = a.data;
		js.msg();
		if(d.upbool){
			js.confirm('有最新版本V'+d.version+'：'+d.desc+'。是否直接在线更新？', function(jg){
				if(jg=='yes')updatejianss();
			});
		}else{
			if(!upb)js.msg('success','当前已是最新版本了');
		}
		js.setoption('lastjcupdate',js.now());
	});
}
function updatejianss(){
	setTimeout("js.alert('系统升级<span id=\"biloss\">(0%...)</span>');",10);
	$.getJSON(getupurl('clientget')+'&version='+version+'',function(ret){
		updaterows = ret.data;
		updatejiansss(0);
	});
}
var updatejianssstime;
function updatejiansss(oi){
	clearTimeout(updatejianssstime);
	if(oi>=updaterows.length){
		$('#biloss').html('<font color=green>升级完成,点头像刷新</font>');
		return;
	}
	var path = updaterows[oi].filepath;
	var spath= path.substr(4);
	var bl   = ((oi+1)/updaterows.length)*100;
	$('#biloss').html('('+js.float(bl)+'%...)<a href="javascipt:;" onclick="updatejiansss('+oi+')">[重试]</a>，文件：'+spath+'');
	nwjs.createdir(spath);
	var url = getupurl('clientgetfile')+'&path='+jm.base64encode(path)+'';
	nwjs.downfile({
		url:url,
		oi:oi,
		savefile:spath,
		onsuccess:function(){
			clearTimeout(updatejianssstime);
			updatejianssstime = setTimeout('updatejiansss('+(this.oi+1)+')',300);
		},
		onerror:function(st){
			clearTimeout(updatejianssstime);
			$('#biloss').html('<font color=red>出错'+st+'</font>,<a href="javascipt:;" onclick="updatejiansss('+this.oi+')">[重试]</a>');
		}
	});
}
function bodyunload(){
	nwjs.removetray();
}
function resize(){
	var tt=$(window).height()-$('.lmaisft').height();
	var ts=(tt*0.5)-10;
	if(ts<10)ts=10;
	$('#topblank').css('height',''+ts+'px');
}
function loginsubmit(lx){
	//apiurl 	= 'http://demo.rockoa.com/';	//这里修改为你自己的系统网址，格式：http://开头,/结尾
	//js.setoption('apiurl', apiurl); 
	if(js.ajaxbool)return false;
	var user = get('adminuser').value;
	var pass = getpassobj().val();
	if(lx==1)temp_token='';
	js.setmsg('');
	if(user==''){
		js.setmsg('用户名不能为空');
		get('adminuser').focus();
		return false;
	}
	if(pass==''&&temp_token==''){
		js.setmsg('密码不能为空');
		getpassobj().focus();
		return false;
	}
	var o = get('btn0');
	o.value='登录中...';
	o.disabled=true;
	js.setoption('adminuser', user);
	js.setmsg('');
	js.ajax('login','check',{user:jm.base64encode(user),pass:jm.base64encode(pass),token:temp_token}, function(da){
		o.value='登录成功';
		loginsuccess(da);
	},'none',false, function(str){
		o.value='登录';
		o.disabled=false;
	});
	return false;
}
function loginsuccess(a){
	js.setoption('adminid',a.uid);
	js.setoption('adminname',a.name);
	js.setoption('adminuser',a.user);
	js.setoption('adminface',a.face);
	js.setoption('admintoken',a.token);
	js.setoption('systemtitle',a.title);
	js.setoption('systemlogo',a.weblogo);
	get('myface').src = a.face;
	js.location('webos.html');
}
function loginset(){
	js.prompt('设置', '您系统地址', function(lx,url){
		if(lx!='yes'||!url)return;
		if(url.substr(url.length-1,1)!='/')url=url+'/';
		js.setoption('apiurl', url);
		apiurl=url;
		changeurl();
		js.msg('success','设置成功');
	}, apiurl);
}
function changeurl(){
	
}
function getpassobj(){
	return $('input[type=password]');
}
</script>
</head>


<body style="background:#66A8E5 url(images/loginbg.jpg) top center no-repeat">
<div align="center">

	<div style="height:50px;overflow:hidden" id="topblank"></div>

	<div class="lmaisft">
		<div class="blank20"></div>
		<div class="ltoplog" align="center"><img onclick="location.reload()" src="images/logo.png" id="myface" align="absmiddle"  height="80" width="80"></div>
		
		<form style="padding:20px;padding-left:60px" name="myform">
			
			<div>
				<div><input type="text" style="height:35px;width:270px" class="input" onKeyUp="if(event.keyCode==13)getpassobj().focus()" maxlength="20" placeholder="请输入用户名/姓名" id="adminuser" name="adminuser" ></div>
			</div>

			<div class="blank20"></div>
			<div>
				<div><input style="height:35px;width:270px" class="input" onKeyUp="if(event.keyCode==13)loginsubmit(1)" value="" type="password" placeholder="请输入密码"></div>
			</div>
			
			<div class="blank10"></div>
			<div>
				<span id="footerts" style="color:#888888;font-size:12px">登录前请先设置&nbsp;<a onclick="return loginset()" href="javascript:">[设置]</a></span>
			</div>
			
			<div class="blank20"></div>

			<div align="left">
				<input type="button" id="btn0" onClick="loginsubmit(1)" class="btn" value="登录">&nbsp;<span id="msgview"></span>
			</div>

		</form>
	
	</div>

</div>
</body>
</html>